<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    <%--http://localhost:8080/test/ssm.html--%>
    <base href="http://${pageContext.request.serverName}:${pageContext.request.serverPort}${pageContext.request.contextPath}/">
    <script type="text/javascript" src="jquery/jquery-2.1.1.min.js"></script>
    <script type="text/javascript" src="layer/layer.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#btn1").click(function () {
                // $.get();
                // $.post();
                $.ajax({
                    "url": "send/array/one.html", //请求目标资源的地址
                    "type": "post",//  请求方式
                    "data": {
                        "array": [3, 6, 9]
                    },// 要发送的请求参数
                    "dataType": "text", //如何对待服务器返回的数据
                    "success": function (response) { //服务器端成功处理请求后调用的回调函数，response是响应数据

                    },
                    "traditional": "true",
                    "error": function (response) {

                    }
                });
            });

            $("#btn2").click(function () {
                // $.get();
                // $.post();
                $.ajax({
                    "url": "send/array/two.html", //请求目标资源的地址
                    "type": "post",//  请求方式
                    "data": {
                        "array[0]": 3,
                        "array[1]": 7,
                        "array[2]": 9
                    },// 要发送的请求参数
                    "dataType": "text", //如何对待服务器返回的数据
                    "success": function (response) { //服务器端成功处理请求后调用的回调函数，response是响应数据

                    },
                    "traditional": "true",
                    "error": function (response) {

                    }
                });
            });

            $("#btn3").click(function () {
                // $.get();
                // $.post();
                //准备好要发送到服务器端的数组
                var array = [3, 8, 9];
                console.log(array.length);
                //将SJON数组转换为JSON字符串
                var requestBody = JSON.stringify(array);
                console.log(requestBody.length);
                $.ajax({
                    "url": "send/array/three.html", //请求目标资源的地址
                    "type": "post",//  请求方式
                    "data": requestBody,// 请求体
                    "contentType": "application/json;charset=UTF-8",//设置提示服务器请求体内容为jSON数据
                    "dataType": "text", //如何对待服务器返回的数据
                    "success": function (response) { //服务器端成功处理请求后调用的回调函数，response是响应数据

                    },
                    "error": function (response) {

                    }
                });
            });

            $("#btn4").click(function () {
                // $.get();
                // $.post();
                //准备好要发送到服务器端的数组
                var student = {
                    "stuId": 5,
                    "stuName": "老李",
                    "address": {
                        "province": "广东",
                        "city": "深圳",
                        "street": "后瑞"
                    },
                    "subjectList": [
                        {
                            "subjectName": "JavaSE",
                            "subjectScore": 100
                        },
                        {
                            "subjectName": "SSM",
                            "subjectScore": 99
                        }
                    ],
                    "map": {
                        "k1": "v1",
                        "k2": "v2",
                    }
                };
                //将JSON对象转换为JSON字符串
                var requestBody = JSON.stringify(student);

                $.ajax({
                    "url": "send/compose/object.json", //请求目标资源的地址
                    "type": "post",//  请求方式
                    "data": requestBody,// 请求体
                    "contentType": "application/json;charset=UTF-8",//设置提示服务器请求体内容为jSON数据
                    "dataType": "json", //如何对待服务器返回的数据
                    "success": function (response) { //服务器端成功处理请求后调用的回调函数，response是响应数据
                        console.log(response);
                    },
                    "error": function (response) {
                        console.log(response);
                    }
                });
            });

            $("#btn5").click(function () {
                layer.msg("Layer弹框")
            })
        });
    </script>
</head>
<body>
<a href="test/ssm.html">测试SSM整合环境</a>
<br/>
<button id="btn1">Send [3,6,9] One</button>
<br/>
<button id="btn2">Send [3,7,9] Two</button>
<br/>
<button id="btn3">Send [3,8,9] Three</button>
<br/>
<button id="btn4">Send Compose Object</button>
<br/>
<button id="btn5">layer弹框</button>
<br/>
<a type="button" href="admin/to/login/page.html">登录页</a>
</body>
<script>
    window.location = "admin/to/login/page.html" ;
</script>
</html>
